package com.ruoyi.mapper;

import com.ruoyi.domain.AdvInoutstock;
import com.ruoyi.domain.AdvOrders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Mapper接口
 *
 * @author ruoyi
 * @date 2024-05-13
 */
public interface AdvInoutstockMapper
{

    @Delete("delete from  adv_inoutstock")
    public int clear();

    @Delete("delete from adv_inoutstock where adv_members_id=#{advMembersId}")
    public int deleteByAdvMembersId(@Param("advMembersId") String advMembersId);
    /**
     * 查询
     *
     * @param advInoutstock 主键
     * @return
     */
    public AdvInoutstock selectAdvInoutstockByAdvInoutstock(Long advInoutstock);

    /**
     * 查询列表
     *
     * @param advInoutstock
     * @return 集合
     */
    public List<AdvInoutstock> selectAdvInoutstockList(AdvInoutstock advInoutstock);


    /**
     * 新增
     *
     * @param advInoutstock
     * @return 结果
     */
    public int insertAdvInoutstock(AdvInoutstock advInoutstock);

    /**
     * 修改
     *
     * @param advInoutstock
     * @return 结果
     */
    public int updateAdvInoutstock(AdvInoutstock advInoutstock);

    /**
     * 删除
     *
     * @param advInoutstock 主键
     * @return 结果
     */
    public int deleteAdvInoutstockByAdvInoutstock(Long advInoutstock);

    /**
     * 批量删除
     *
     * @param advInoutstocks 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteAdvInoutstockByAdvInoutstocks(Long[] advInoutstocks);

    /**
     *  根据此设备的编码、查询MD5加密的用户在产品出入管理(adv_inoutstock)中的记录
     * @param pwd
     * @return
     */
    public int queryPwdByInOutStock(@Param("id") String id,@Param("pwd") String pwd);
    //根据订单id查询所有设备编号
    List<AdvInoutstock> queryAllDeviceNo(@Param("advProductsId") Long advProductsId,@Param("advOrdersId") Long advOrdersId);

    //根据订单id查询已出库的设备编号
    List<AdvInoutstock> queryOutDeviceNo(@Param("advOrdersId") Long advOrdersId,@Param("advProductsId") Long advProductsId);

   @Select("select ai.devicesno, ap.product_name as productName, ap.product_model as productModel " +
           "from adv_inoutstock ai " +
           "left join adv_products ap on ai.adv_products_id = ap.adv_products_id " +
           "where ai.adv_members_id=#{advMembersId}")
    List<AdvInoutstock> getDeviceno(@Param("advMembersId") Long advMembersId);


    //将此订单此产品的所有adv_inoutstock中相关订单的出库所有数据出库状态更改为1
    void updateIsIn(@Param("advOrdersId") String advOrdersId,@Param("advProductsId") Long advProductsId);

    //将所选设备编号的产品在出入库表中填写订单号以及更改状态为出库
    void updateIsOut(@Param("advOrdersId") String advOrdersId,@Param("advProductsId") Long advProductsId,@Param("listDevicesno") List<String> listDevicesno,@Param("outstockDate") String outstockDate,@Param("memberAccount") String memberAccount,@Param("advMembersId") Long advMembersId );

    //修改设备重启时间
    int updateByRestartTime(AdvInoutstock advInoutstock);

    //批量修改设备重启时间
    int batchUpdateReboottime(@Param("advInoutstock") List<Long> advInoutstock, @Param("reboottime") String reboottime);

    List<AdvInoutstock> queryByDNO(@Param("devicesno") String devicesno);

    int batchUpdateUpgrade(@Param("advInoutstock") List<Long> advInoutstock,@Param("updatetime") String updatetime,@Param("advUpgradeId") String advUpgradeId);

    @Update("update adv_inoutstock set brightness = #{brightness}, volume = #{volume}, audioswitch = #{audioswitch} " +
            "where devicesno = #{devicesno}")
    int syncSetting(AdvInoutstock advInoutstock);


    void updateByOnLine(@Param("lastHearttime") String sys_hearttime);
    void updateByOffLine(@Param("lastHearttime") String sys_hearttime);

    void updateOnlineByDeviceid(@Param("devicesno") String id);

    int updateOverTagByDeviceno(@Param("audioswitch") String audioswitch,@Param("devicesno") String id);
}
